#include "Fifo.hpp"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <cstring>
#include <fcntl.h>
#include <iostream>
#include <cerrno>

int main()
{
    Fifo fifo(Path);

    int rfd = open(Path, O_RDONLY);
    cout << "read_open" << endl;
    if (rfd < 0)
    {
        cerr << "open error:" << errno << endl;
        return 1;
    }
    char buf[64];
    while (1)
    {
        memset(buf, 0, sizeof(buf));

        int n = read(rfd, buf, sizeof(buf));
        if (n > 0)
            cout << "server get message:" << buf << endl;

        else if (n == 0)
        {
            cout << "server read end!" << endl;
            break;
        }
        else
        {
            cerr << "server read error: " << errno << endl;
            break;
        }
    }
    close(rfd);
    cout << "read close" << endl;
    return 0;
}